package com.ghck.server.service.impl;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ghck.server.dao.LoginLogMapper;
import com.ghck.server.model.LoginLog;
import com.ghck.server.model.query.LoginLogQuery;
import com.ghck.server.service.LoginLogService;

/**
 * 登录日志表  <br>
 * login_log <br>
 * v1.0 2016-05-01
 */
 @Service
 @Transactional
 public class LoginLogServiceImpl implements LoginLogService {
	
	private static final Logger logger = LoggerFactory.getLogger(LoginLogServiceImpl.class);
	
	@Autowired
	private LoginLogMapper loginLogMapper;
	
	/**
 	*根据ID删除 登录日志表
 	*/
 	@Override
 	public Integer deleteLoginLogById(Integer id){
 		return loginLogMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 登录日志表
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertLoginLog(List<? extends LoginLog> loginLogs){
		Integer count = loginLogMapper.batchInsert(loginLogs);
		return count;
 	}
 	/**
 	*新增 登录日志表
 	*/
 	@Override
 	@Transactional
 	public Integer insertLoginLog(LoginLog domain){
		Integer id = loginLogMapper.insert(domain);
		return id;
 	}

 	/**
 	*更新 登录日志表
 	*/
 	@Override
 	@Transactional
 	public Integer updateLoginLog(LoginLog domain){
		Integer count = loginLogMapper.update(domain);
		return count;
 	}
 	
 	/**
 	*根据ID查询 登录日志表
 	*/
 	public LoginLog findLoginLogById(Integer id){
 		LoginLog result = loginLogMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 登录日志表
 	*/
	public List<LoginLog> findLoginLogByQuery(LoginLogQuery query){
		query.dealWith();
		List<LoginLog> result = loginLogMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (LoginLog loginLog : result) {
				loginLog.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countLoginLogByQuery(LoginLogQuery query){
 		query.dealWith();
 		Integer result = loginLogMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<LoginLog> findLoginLogByIds(List<Integer> ids){
 		List<LoginLog> result = loginLogMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (LoginLog loginLog : result) {
				loginLog.dealWith();
			}
		}
		return result;
 	}
 	
}	